﻿
/**
 * 异步加载列表数据
 */
function list(pageNo,whereValue)
{
	var url = getAction()+"?cmd=data&"+getForm().formSerialize();
	$.ajax({
		type: "POST",
		url: url,
		dateType: "html",
		success: function(returnedData){
			$$("dataList").innerHTML = returnedData;
			initParentIFrame();
		}
	});
}


function getAction(){
	return "CommLinkAction.action";
}

function getForm()
{
	return $("#CommLinkActionForm");
}

function getDomForm(){
	return $$("CommLinkActionForm");
}

/*
 * 跳转到添加页面
 */
function goAdd(){
	var retValue = window.showModalDialog(getAction()+"?cmd=goAdd&param="+$$("param").value,window,"dialogWidth:550px;dialogHeight:250px;resizable=no","menubar=no;toolbar=no");
}

/*
 * 添加操作，然后返回list页面
 */
function add(){
	if(!validateForm()) return;
	$("#CommLinkActionForm").ajaxSubmit({
			dataType:"html",
			success : function(returnedData, statusText, xhr, $form) {
			returnedData = $.evalJSON(returnedData);
			if(returnedData.msg){
				alert(returnedData.msg);
			}
			if(returnedData.processId=='1'){
				var parentWindow = window.dialogArguments;
				parentWindow.list(1);
				window.close();
			}
		}
	});
}


/**
 * 添加后返回添加页面继续添加一个记录
 */
function addNext()
{
	if(!validateForm())	return;
	var url = getAction()+"?"+serializeForm(getDomForm());
	saveOrUpdate(url,"addNext");

}

/**
 * 跳转到更新页面
 */
function goUpdate(id)
{
	var retValue = window.showModalDialog(getAction()+"?cmd=goUpdate&po.id="+id+"&param="+$$("param").value,window,"dialogWidth:550px;dialogHeight:250px;resizable=no","menubar=no;toolbar=no");
}
 
/**
 * 更新一条记录
 */
function update()
{
	if(!validateForm()) return;
	//var url = getAction()+"?"+serializeForm(getDomForm());
	
	$("#CommLinkActionForm").ajaxSubmit({
			dataType:"html",
			success : function(returnedData, statusText, xhr, $form) {
			returnedData = $.evalJSON(returnedData);
			if(returnedData.msg){
				alert(returnedData.msg);
			}
			if(returnedData.processId=='1'){
				var parentWindow = window.dialogArguments;
				parentWindow.list(1);
				window.close();
			}
		}
	});
	
	
	
}

function saveOrUpdate(url,type){
	$.ajax({
		type: "POST",
		url: url,
		dateType: "html",
		success: function(returnedData){
			returnedData = $.evalJSON(returnedData);
			alert(returnedData.msg);
			if(returnedData.processId=='1'){
				var parentWindow = window.dialogArguments;
				parentWindow.list(1);
			}
			if(type !== 'addNext' )	//未定义
				window.close();
			getForm().reset();		//重置
		}
	});
}

/**
 * 表单域校验
 */ 
function validateForm()
{
	var success = true;
	
	if(!checkBlank($$("po.linkName"),"链接名称"))
	{
		success = false;
	}
	else if(!checkBlank($$("po.path"),"网址"))
	{
		success = false;
	} else if(checkWebAddress($$("po.path").value)){
		success = false;
	}
	
	return success;
}


function del(id){
	if(confirm("您确定要删除这些数据么？")==false)
		return;
	var url = getAction()+"?cmd=delete&formMap.ids="+id;
	$.ajax({
		type: "POST",
		url: url,
		dateType: "html",
		success: function(returnedData){
			returnedData = $.evalJSON(returnedData);
			alert(returnedData.msg);
			if(returnedData.processId=='1'){
				list(1);
			}
		}
	});
}


